// TOWN SCRIPT
//    Town 1: Cresent Entry

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i, choice;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);

	set_name(12, "Jonathan");
	set_char_dialogue_pic(12, 1948, 0);
	set_name(13, "Smithers");
	set_char_dialogue_pic(13, 1945, 0);

	// check quest flags and process...
	if (get_flag(50, 0) == 0) {
		// give main quest when first starting out
		toggle_quest(0, 1);
		set_flag(50, 0, 1);
	}
	if (get_flag(50, 1) > 0) {
		message_dialog("You wearily enter Cresent Entry with the she-devil problem resolved.",
			"Through the west gate is the way out of Cresent Valley and more adventures elsewhere.");
	}
break;

beginstate EXIT_STATE;
	if (get_flag(1, 1) == 0) {
		set_flag(1, 1, 1);
		reset_dialog();
		add_dialog_str(0, "You exit out into Cresent Valley with determination.", 0);
		add_dialog_str(1, "Somehow, you need to find and deal with the creature plaguing Cresent Valley.", 0);
		add_dialog_str(2, "Perhaps the best place to start would be the Ben's home town of Cresent Harbor which lies to the northeast.", 0);
		add_dialog_str(3, "But first, you feel you should check in with Ben camping just outside of Cresent Entry.", 0);
		add_dialog_choice(0, "OK");
		choice = run_dialog(1);
	}
break;

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 6)
		text_bubble_on_char(6, "Watch your step.");
	if (get_ran(1, 0, 100) < 6)
		text_bubble_on_char(7, "Stay out of trouble.");
	if (get_ran(1, 0, 100) < 6) {
		if (get_flag(50, 1) == 0)
			text_bubble_on_char(8, "Beware the she-devil.");
		else
			text_bubble_on_char(8, "Good job.");
	}
	if (get_ran(1, 0, 100) < 6)
		text_bubble_on_char(9, "Don't steal.");
	if (get_ran(1, 0, 100) < 6)
		text_bubble_on_char(10, "Watch it.");
	if (get_ran(1, 0, 100) < 6)
		text_bubble_on_char(11, "Don't cause trouble.");
break;

beginstate 10;
	reset_dialog();
	if (get_flag(50, 1) == 0)
		add_dialog_str(0, "The she-devil continues to prowl Cresent Valley!", 0);
	else
		add_dialog_str(0, "You are ready for other adventures.", 0);
	add_dialog_str(1, "Do you wish to leave the scenario?", 0);
	add_dialog_choice(0, "Not yet. I want to continue to explore.");
	add_dialog_choice(1, "Yes. I am done here.");
	choice = run_dialog(1);
	if (choice == 1)
		block_entry(1);
	if (choice == 2)
		set_state_continue(11);
break;

beginstate 11;
	// return Demonslayer if you have it...
	if (get_flag(13, 3) > 0) {
		reset_dialog();
		if (get_flag(13, 3) > 1) {
			add_dialog_str(0, "Before you can get through the gate, a guard stops you.", 0);
			add_dialog_str(1, "He quickly pats you down, then seizes Demonslayer before you can do anything.", 0);
			add_dialog_str(2, "_This is contraband and doesn't belong to you._ he says after taking the weapon.", 0);
			add_dialog_str(3, "With the seizure complete, the party is released to continue it's exit.", 0);
		}
		else {
			add_dialog_str(0, "You are surprised to see Terra from Aries standing by the gate out of Cresent Valley.", 0);
			add_dialog_str(1, "You suddenly realize that the 'secret spy entrance' really wasn't much of a secret to the Avernumians.", 0);
			add_dialog_str(2, "After a little small talk, she asks you for Demonslayer back.", 0);
			add_dialog_str(3, "Since the weapon was a loan, you, with great sadness, return it to her.", 0);
			add_dialog_str(4, "With the weapon in hand, she thanks you again for the help and leaves.", 0);
		}
		add_dialog_choice(0, "OK");
		choice = run_dialog(1);
		take_item(450);
	}
	set_state_continue(13);
break;

beginstate 12;
	if (get_flag(1, 0) == 0) {
		message_dialog("The guard at the gate blocks your path.",
			"_You cannot enter Cresent Valley without permission.  See the entry official._");
		block_entry(1);
	}
	else {
		block_entry(0);
	}
break;

beginstate 13;
	// complete or not, give appropriate message
	if (get_flag(50, 1) == 0) {
		message_dialog("You leave knowing that you failed Ben and yourself.",
"The she-devil was too much for you, but you may be back.");
		end_scenario(0);
	}
	else {
		i = 2;
		reset_dialog();
		add_dialog_str(0, "You accomplished what you set out to do in Cresent Valley.", 0);
		add_dialog_str(1, "You've dealt with the she-devil that was plaguing the region.", 0);
		if (get_flag(50, 9) > 0) {
			add_dialog_str(i, "Though you somehow feel that you didn't need to kill her to deal with her.", 0);
			i = i + 1;
		}
		add_dialog_str(i, "Now that she has been dealt with, the empire will lift the quarantine allowing trade to once again bring prosperity back to Cresent Valley.", 0);
		if (get_flag(11, 8) > 0) {
			add_dialog_str(i, "In addition, you were able to deal with a bandit problem.", 0);
			i = i + 1;
		}
		if (get_flag(50, 5) > 0) {
			add_dialog_str(i, "You also removed an undead problem that had managed take root with the appearance of the she-devil.", 0);
			i = i + 1;
		}
		if ((get_flag(50, 3) > 0) || (get_flag(50, 7) > 0)) {
			add_dialog_str(i, "And you were able to help some people with other problems.", 0);
			i = i + 1;
		}
		add_dialog_str(i, "You leave feeling good about the future of Cresent Valley and it's citizens.", 0);
		i = i + 1;
		add_dialog_str(i, " - FIN -", 40);
		add_dialog_choice(0, "OK.");
		choice = run_dialog(1);
		end_scenario(1);
	}
break;

beginstate 14;
	message_dialog("The bookshelf contains a collection of novels and empire papers.", "There's nothing that will help your quest though.");
break;
